<!-- 已完成；换行功能 计时功能-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery-1.8.0.js"></script>
</head>
<body>
    <span>这是读取并渲染txt文件内容示例</span>
    <br>
    <button type="button" onclick="readTxt()">读取500行</button>
    <button type="button" onclick="readTxt2()">读取1000行</button>
    <button type="button" onclick="start()">计时开始</button>
    <button type="button" onclick="end()">计时结束</button>
    <div class="box"></div>


    <script>
       //计时
          
         function start(){
            t=0
             interval = setInterval(function(){
                t++
                //console.log("t="+t)
            },1)
         }
         function end(){
            
             clearInterval(interval)
             alert("用时："+t+"ms")
             time = t
         }
    </script>

    <script>
         

















        var startT=0
        function readTxt() {
            //start()








            document.querySelector(".box").innerHTML=""
            $.get('https://xinguanbang.github.io/test/testcode1/langtext500.txt',function(data) {  


                var lines = data.split("\n"); //按行读取

                $.each(lines,function(i, v) {
                    if(v==""){
                        v='<br>'
                    }else{
                        v=v+'<br>'
                    }
                    var D = document.querySelector(".box").innerHTML
                    document.querySelector(".box").innerHTML=D+v
                });
                //end()














                //alert("已读取500行！用时："+time+"ms")
                alert("已读取500行！")

            });
        }
        function readTxt2() {
            //start()
            document.querySelector(".box").innerHTML=""
            $.get('https://xinguanbang.github.io/test/testcode1/langtext1000.txt',function(data) {  


                var lines = data.split("\n"); //按行读取

                $.each(lines,function(i, v) {
                    if(v==""){
                        v='<br>'
                    }else{
                        v=v+'<br>'
                    }
                    var D = document.querySelector(".box").innerHTML
                    document.querySelector(".box").innerHTML=D+v
                });
                //end()
                //alert("已读取1000行！用时："+time+"ms")
                alert("已读取1000行！")


            });
        }











        
    </script>
    
</body>
</html>
